package com.zht.demo;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.Comparator;

public class 淄博照片接口测试 {
    public static void main(String[] args) {
        String json = "{\n" +
                "    \"result\":{\n" +
                "        \"DQYM\":1,\n" +
                "        \"DYTS\":10,\n" +
                "        \"FHZ\":[\n" +
                "            {\n" +
                "                \"image\":\"ksdfkjshdfjksdhkjhdkjgbsdkjvbsdkjvbkjsdb\",\n" +
                "                \"when_registered\":\"1565767466000\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"image\":\"ksdfkjshdfjksdhkjhdkjgbsdkjvbsdkjvbkjsdb111111111111111111\",\n" +
                "                \"when_registered\":\"1699343090000\"\n" +
                "            },\n" +
                "{\n" +
                "                \"image\":\"ksdfkjshdfjksdhkjhdkjgbsdkjvbsdkjvbkjsdb\",\n" +
                "                \"when_registered\":\"1638863233000\"\n" +
                "            }\n" +
                "        ],\n" +
                "        \"CXSJL\":2\n" +
                "    },\n" +
                "    \"code\":200,\n" +
                "    \"success\":true,\n" +
                "    \"message\":\"ok\"\n" +
                "}";

        JSONObject jsonObject = JSONObject.parseObject(json);
        System.out.println(jsonObject.toJSONString());
        if ("ok".equals(jsonObject.get("message"))) {
            JSONObject resultData = (JSONObject) jsonObject.get("result");
            JSONArray zpfhz = resultData.getJSONArray("FHZ");
            zpfhz.sort(Comparator.comparing(obj -> ((JSONObject)obj).getDate("when_registered")).reversed());
            String imageBase64 = zpfhz.getJSONObject(0).getString("image");
            System.out.println(imageBase64);
        }
    }
}
